package com.project.medical.sys.controller;


import com.project.medical.sys.common.utils.R;
import com.project.medical.sys.entity.TokenEntity;
import com.project.medical.sys.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("sys/login")
public class LoginController {
    @Autowired
    ManagerService managerService;

    @RequestMapping("/adminLogin")
    public R adminLogin(@RequestBody Map<String, Object> params){
        TokenEntity token = managerService.login(params);
        if (token!=null)return R.ok().put("token", token);
        return R.error();


    }

    @RequestMapping("/checkToken")
    public R list(@RequestParam Map<String, Object> params){
        boolean res = managerService.checkToken(params);
        if (res) return R.ok();
        return R.error();
    }
    @RequestMapping("/unLogin")
    public R unLogin(){
        return R.error(401,"请登录");
    }
}
